package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqAutoChangeModeResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.entity.MqSleepTimeAutoChange;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class AutoChangeWorkModeReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // // *WT,866248050395985,V4,SLEEPTIME,172643,02:00,03:00,1,A,2250.2269,N,11391.6194,E,0.15,0,020621,FFFFDFFF
//        String str = data.substring(0, data.length() - 1); //将指令末尾的#截取掉
        //分割字符串获取指令信息
        String[] split = data.split(",");
        String imei = split[1];
        String messageType=split[2];
        String type=split[3];
        String commandNumber = split[4];
        String startTime=split[5];//开始时间
        String endTime = split[6];//结束时间
        String flag = split[7];//功能的开关 0-关闭 1-开启
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];//日月年
        String deviceStatus = split[16];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqSleepTimeAutoChange mqSleepTimeAutoChange = new MqSleepTimeAutoChange();
        mqSleepTimeAutoChange.setFlag(Integer.parseInt(flag));
        mqSleepTimeAutoChange.setStart(startTime);
        mqSleepTimeAutoChange.setEnd(endTime);
        mqSleepTimeAutoChange.setImei(imei);
        mqSleepTimeAutoChange.setCommandNumber(commandNumber);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        MqAutoChangeModeResult mqAutoChangeModeResult = new MqAutoChangeModeResult();
        mqAutoChangeModeResult.setMqLocationData(mqLocationData);
        mqAutoChangeModeResult.setMqSleepTimeAutoChange(mqSleepTimeAutoChange);
        InjectFeignService.getIrmFeignClientService().sleepAutoChangeModeResponse(mqAutoChangeModeResult);
        return imei;
    }
}
